<?php

namespace app\shop\library\response;

use think\response\Json;

class Response
{
    /**
     * 构造Json响应数据
     * @param int    $statusCode   状态码
     * @param mixed  $data         响应数据
     * @param string $msg          响应信息
     * @param int    $businessCode 业务状态码
     * @return Json
     */
    public static function buildJson(int $statusCode, mixed $data = [], string $msg = '', int $businessCode = 0): Json
    {
        $result = [
            'code'   => $businessCode ?: $statusCode,
            'msg'    => $msg,
            'time'   => request()->server('REQUEST_TIME'),
            'result' => $data,
        ];

        return json($result, $statusCode);
    }
}